package com.sjksy.demo.xxl_job;

import com.sjksy.demo.service.FinanceSummaryService;
import com.sjksy.demo.service.LedgerService;
import com.sjksy.demo.vo.ledger.LedgerBranchStatisticVo;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class XxlJobHandler {

    @Resource
    LedgerService ledgerService;

    @Resource
    FinanceSummaryService financeSummaryService;

//    传参，分布式集群调用等等还待研究,cron会玩了至少
    @XxlJob("recordStatisticBranchLedger")
    void recordStatisticBranchLedger(){
        try{
            List<LedgerBranchStatisticVo> ledgerBranchStatisticVoList = ledgerService.statisticBranchLedger();
            if(!financeSummaryService.recordStatisticBranchLedger(ledgerBranchStatisticVoList)){
                throw new RuntimeException("recordStatisticBranchLedger err!!");
            }
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
    }

}
